package com.shunwang.errors.engine.builder.bean;

import java.util.ArrayList;
import java.util.List;

public class NodeMethod {

	private String methodName;
	private List<StringBuffer> exClazz = new ArrayList<StringBuffer>();
	private String handClazz;
	public String getMethodName() {
		return methodName;
	}
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}
	public String getHandClazz() {
		return handClazz;
	}
	public void setHandClazz(String handClazz) {
		this.handClazz = handClazz;
	}
	public List<StringBuffer> getExClazz() {
		return exClazz;
	}
	public void setExClazz(List<StringBuffer> exClazz) {
		this.exClazz = exClazz;
	}
	
	public boolean contains(String method,String handler){
		return methodName.equals(method) && handClazz.equals(handler);
	}
	public boolean contains(String throwable){
		for(StringBuffer sb2:this.exClazz){
			if(throwable.equals(sb2.toString())){
				return true;
			}
		}
		return false;
	}
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof NodeMethod)){
			return false;
		}
		NodeMethod bean = (NodeMethod)obj;
		if(checkMethod(bean) && checkHandler(bean) && checkThrowable(bean)){
			return true;
		}
		return false;
	}
	
	private boolean checkThrowable(NodeMethod obj){
		for(StringBuffer sb:obj.exClazz){
			for(StringBuffer sb2:this.exClazz){
				if(sb.toString().equals(sb2.toString())){
					return true;
				}
			}
		}
		return false;
	}
	
	private boolean checkMethod(NodeMethod obj){
		return this.methodName.equals(obj.methodName);
	}
	
	private boolean checkHandler(NodeMethod obj){
		return this.handClazz.equals(obj.handClazz);
	}
	
}
